﻿
using UnityEngine;
namespace WzhModule.GM
{
    public class WzhGMAdaptiveBangs : MonoBehaviour
    {
        [Header("是否是竖版游戏")]
        public bool IsPortrait = true;
        [Header("手机是否拥有刘海")]
        private bool IsBangs;
        [Header("刘海像素")]
        private float BangsPixel;
        [Header("是否需要刘海屏适配")]
        public bool IsNeedAdaptiveBangs;

        [Header("开启双端适配")]
        public bool IsDoubleEnded;

        public static float currScreenRote;

        private void Start()
        {
            AdaptiveIphone(base.gameObject);
        }

        //    需要适配的View
        private void AdaptiveIphone(GameObject gameObject)
        {
            RectTransform component = gameObject.GetComponent<RectTransform>();
            int num = AdaptiveIphoneInit();
            Debug.Log("刘海屏适配高度:" + num);
            BangsPixel = num;
            IsBangs = (BangsPixel != 0f);

            if (!IsNeedAdaptiveBangs) return;

            if (IsPortrait)
            {
                component.offsetMax = new Vector2(component.offsetMax.x, component.offsetMax.y - (float)num);
                if (IsDoubleEnded)
                {
                    component.offsetMin = new Vector2(component.offsetMin.x, component.offsetMin.y + (float)num);
                }
            }
            else
            {
                component.offsetMin = new Vector2(component.offsetMin.x + (float)num, component.offsetMin.y);
                if (IsDoubleEnded)
                {
                    component.offsetMax = new Vector2(component.offsetMax.x - (float)num, component.offsetMax.y);
                }
            }
        }

        //     获取是否是刘海屏，并给高赋值
        private int AdaptiveIphoneInit()
        {
            int result = 0;
            // 判断是否是刘海屏
            float currScreenRote = ((!IsPortrait) ? ((float)Screen.width / (float)Screen.height) : ((float)Screen.height / (float)Screen.width));
            if (currScreenRote > 2f) result = 85;
            return result;
        }
    }
}
